package com.example.allplan.RecyclerAdapter;

import android.content.ContentValues;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.allplan.JavaBean.JiHuaBaoJavaBean;
import com.example.allplan.R;
import com.example.allplan.StaticFangfa.BiaoQingZhuanHuan;

import java.util.ArrayList;

public class JiHuaBaoRecyclerAdapter extends RecyclerView.Adapter<JiHuaBaoRecyclerAdapter.ViewHolder> {

    ArrayList<JiHuaBaoJavaBean> mList;
    onItemClickListener mListener;
    Context mcon;
    public JiHuaBaoRecyclerAdapter(ArrayList<JiHuaBaoJavaBean> m, onItemClickListener mL, Context mcon){
        mListener=mL;
        mList=m;
        this.mcon=mcon;
    }
       public void setlist(ArrayList<JiHuaBaoJavaBean> ml){
        mList=ml;
        }


    public interface onItemClickListener{
        void onClick(int pos, Context mcon);
    }
    public JiHuaBaoRecyclerAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.ji_hua_bao_item_view, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull final JiHuaBaoRecyclerAdapter.ViewHolder holder, final int position) {
        holder.biao_qing_textview.setText(BiaoQingZhuanHuan.biao_qing_int_to_string(mList.get(position).getBiao_qing_fu_hao_zhi()));
        holder.bao_ming_textview.setText(mList.get(position).getBao_ming());
        holder.item_linear_view.setOnClickListener(new View.OnClickListener() {
            @Override
            synchronized public void  onClick(View v) {
                mListener.onClick(holder.getLayoutPosition(),mcon);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView biao_qing_textview,bao_ming_textview;
        LinearLayout item_linear_view;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            biao_qing_textview=itemView.findViewById(R.id.ji_hua_bao_biao_qing_textview);
            bao_ming_textview=itemView.findViewById(R.id.yi_tiao_ji_hua_bao_item_textview);
            item_linear_view=itemView.findViewById(R.id.ji_hua_bao_item_linearview);
        }

    }
}
